package cn.xiaoxiang.aop1;

import cn.xiaoxiang.org.domain.Log;
import cn.xiaoxiang.org.mapper.LogMapper;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.Date;

@Aspect
@Component
@Slf4j
class PethomeManager {
//    @Pointcut("@annotation(cn.xiaoxiang.aop1.PethomeAop)")
//    public void pointcut() {}
//    @Autowired
//    private LogMapper logMapper;
//    @Around("pointcut()")
//    public Object around(ProceedingJoinPoint pjp) throws Throwable {
//        MethodSignature methodSignature = (MethodSignature) pjp.getSignature();
//        Method method = methodSignature.getMethod();
//        //获取自定义注解的值
//        PethomeAop annotation = method.getAnnotation(PethomeAop.class);
//        String name = annotation.name();
//        log.info("方法名称：{}", name);
//        //获取方法名
//        String methdName = method.getName();
//        //获取ip
//        InetAddress localHost = Inet4Address.getLocalHost();
//        String ip = localHost.getHostAddress();
//        Log log = new Log();
//        //赋值
//        log.setName(name);
//        log.setMethdName(methdName);
//        log.setIp(ip);
//        log.setTime(new Date());
//
//
//        Object proceed = pjp.proceed();
//        logMapper.add(log);
//        return proceed;
//    }



}
